<template>
    <div>
        <van-card v-for="order in orders"
                :price=order.price
                :desc=order.create_time
                :title=order.name
                :thumb=order.pic
                  @click="toOrder(order.id)"
        >
            <template #footer>
                <van-button @click.stop="deleteOrder(order.id)">删除订单</van-button>
                <van-button @click.stop="appraise(order.id)">评价</van-button>
            </template>
        </van-card>

        <div style="height: 50px"></div>
    </div>
</template>

<script>
    export default {
        name: "List",
        data(){
            return {
                orders:[], //id,name,pic,create_time
            }
        },
        methods:{
            toOrder(id){
                this.$router.push({
                    path:'/listItem',
                    query:{
                        id
                    }
                })
            },
            deleteOrder(id){
                console.log(1)
                // for (let index in this.orders) {
                //     if(this.orders[index].id === id){
                //         this.orders.splice(index,1);
                //     }
                // }
            },
            appraise(){
                console.log(2)
            }
        },
        mounted() {
            console.log("==>OrderList");
            this.$axios.post('/orderList',{
                buyerId: this.$store.state.buyerId
            }).then(res=>{
                // console.log(res.data);
                this.orders = res.data;
                for (let o of this.orders) {
                    o.create_time = this.$moment(o.create_time).format('YYYY-MM-DD HH:mm:ss');
                }

            })
        }

    }
</script>

<style scoped>

</style>